package com.smh.mianshi.initialize;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author shiminghui
 * @date 2024/10/8 16:33
 * @description: TODO
 */
@Component
public class MyInitialize implements InitializingBean, DisposableBean {
//注解方法要早于实现方法执行
//注解方法在加载beanPostProcessor执行时候执行
//实现方法在beanPostProcessor执行完之后执行
    @PostConstruct
    public void init() {
        //bean 初始化时候调用
        System.out.println("MyInitialize初始化 init,通过注解");
    }

    @PreDestroy
    public void destroy1() {
        //bean 销毁时候调用
        System.out.println("MyInitialize销毁,通过注解");
    }


    @Override
    public void destroy() throws Exception {
        //bean 销毁时候调用
        System.out.println("MyInitialize销毁");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        //bean 初始化时候调用
        System.out.println("MyInitialize初始化");
    }
}
